I try a rule for commerce along the lines of following pseudo pattern:
________________________________
Event: After updating an existing commerce product
Conditions: commerce-product:type == 'myProductType'
Actions:
- Load related entities(entity:[commerce-product], relation type:'myRelationType'), provide var: entity_list
- Loop: entity_list AS entity_list_item
________________________________
I would have assumed, that this allows me to target fields of the loaded entities (product display nodes), to inject (set) data sourced from my comerce-product. I can not get this done - there are no tokens for the fields that live on my display nodes.
I'd be most grateful if anyone can point me in the right direction, or just tell me in case it can not be done, so I can stop churning through the entire interweb.
Comments
Comment #1
acrazyanimal commentedI have been running into this issue since I started using the relation module. Stellar job on the relation module btw!
I've found several problems with the
Loads related entitiesaction. The first is that it returns a generic entity list so rules has no idea what fields might be available to it. The second is that the values in the list it does return are not the entity objects themselves, but the wrapped entity metadata structures. So even if you did specify the type of the returned entity list attempts to access the data would fail on execution. At least that is what I've found.I've created a patch to fix both these problems. So an optional entity type parameter has been added. I've tested it on existing rules that use the
Loads related entitiesaction and it seems to upgrade just fine. I don't think changing the return format from the wrapper to the entity object will affect any existing rules since they weren't working before, but it may if anybody has written custom code to extract the info from the returned list. I would say this is a beware for people upgrading, but probably not all that common. By specifying an entity type to return it now allows you to access the functions directly in rules.I'm attaching a second patch that includes both the above fixes and a new action
Fetch relation endpointsto return related entities of a specific type found in a particular relation. This is needed as often I want to alter data on an existing relation or operate on its endpoints. TheLoads related entitiesfunction doesn't allow you to be relation specific, nor would the endpoints [token] field. The coolest thing (IMHO) about this function is that it returns a single entity if you only select 1 in the How Many parameter or a list of entities of a specific type otherwise.This also, address all the requests by @Itangalo in #1260262: More Rules actions! minus #4.
Comment #3
acrazyanimal commentedThis is in fact a bug, upping it to major only because I image many people are having this frustration and are hitting a wall if they are not a developer.
btw, the above patches are against the latest dev as of today.
Comment #4
acrazyanimal commented#1: relation-loads-related-entities-fix-1361796.patch queued for re-testing.
Comment #5
acrazyanimal commented#1: relation-loads-related-entities-fix-plus-bonus-action-1361796.patch queued for re-testing.
Comment #6
7wonders commentedWhen using the "Loads related entities" after applying the 2nd patch, I get the following when going to pick the relation type:
Comment #7
acrazyanimal commented@7wonders: which version did you apply the patch against. The patches I created were to be applied against dev back when I first posted them. Its likely they have diverged again and a new patch will be needed.
Comment #8
7wonders commentedAgainst the latest dev
Comment #9
chx commentedRe-uploading the patch, it seemed to apply for me.
Comment #10
chx commentedSo, at least this passes tests (which means little cos the bot doesnt run the rules tests). acrazyanimal, 7wonders please report back whether it still works.
Comment #11
acrazyanimal commented@chx: I just applied the patch against the latest dev and received the same error reported by 7wonders when editing an existing rule already configured to use the "Loads related entities".
I will investigate further...
Comment #12
chx commentedTHanks for the report! It's unlikely I can find the time to debug this any time soon so special thanks for investigating further.
Comment #13
acrazyanimal commentedGot it. Missing array []. Not sure how that happened, it was done right on my initial copy. I must have messed it up before making the patch somehow??? weird.
Anyway, try testing this version out.
Comment #14
7wonders commentedyep, that did the job ;)
Comment #15
chx commented#13: relation-loads-related-entities-fix-plus-bonus-action-1361796_6.patch queued for re-testing.
Comment #16
chx commentedOh crap I accidentally committed the previous one with the UI separation! Fixing.
Comment #17
chx commentedCommitted, thanks.
Comment #18
acrazyanimal commentedbollocks! chx you messed up my authorship cred ... its cool, accidents happen. Thanks for committing. ;)
Comment #19
chx commentedI did? How so?
Comment #20
acrazyanimal commentedThe patch I gave you was git commit aware and had my author info included in it. You committed the changes along with your 'Separate API and UI modules' changes and no cred was attributed to me whatsoever for actually doing the work to fix the 'Loads related entities' and adding the new 'Fetch relation endpoints' action. Stings a little to put effort into something, but not get the credit due. I'm sure you understand.
Commit c04134c on 7.x-1.x
by chx
Separate API and UI modules.
You did add my name to the commit after it for fixing the [], but still no authorship.
Adding a commit author
Comment #21
chx commentedI will take more care of this. Believe me, I understand more than you'd think how much this matters.
Comment #22
chx commentedI have re-committed this so that you got your credit. Thanks for your work.
Comment #23
acrazyanimal commentedThanks chx, I appreciate the effort. :) I also appreciate this amazing module! Good work guys.
Comment #25
nicodv commentedFirst, thanks to everyone involved in the creation and following development of this module, I've been having fun using it, although I recently ran into a problem related to what's been talked here:
I created a rule that relates a user with an OG group (relation type: "is tutor of"). Now I want to provide another rule for when that person stops being a tutor for that group, so I go to rules and try to use "loads related entities" but there is no way to find the exact relation of the current user and his/her group.
In few words: how do you delete a relation from rules?
thanks again, hope I explained myself and that someone can help here.
nico
Comment #26
chx commentedPlease file a separate support issue.
Comment #27
nicodv commentedi will
thanks